<template>
  <div class="page-home">
    <div class="home-entry">
      <div class="container">
        <!-- 左侧分类 -->
        <HomeCategory />
        <!-- banner轮播图 -->
        <HomeBanner />
        <!-- 新鲜好物 -->
        <home-panel title="新鲜好物" subTitle="新鲜出炉 品质靠谱">

          <template #right>
            <XtxMore></XtxMore>
          </template>

          <template #main>
            <ul ref="pannel" class="goods-list">
              <li v-for="item in newDate" :key="item.id">
                <RouterLink :to="`/goods/${item.id}`">
                  <img  alt="" :src='item.picture' />
                  <p class="name">{{ item.name }}</p>
                  <p class="price">&yen;{{ item.price }}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </home-panel>
        <!-- 人气推荐 -->
        <home-panel title="人气推荐" sub-title="人气爆款 不容错过">
          <template #right>
            <XtxMore></XtxMore>
          </template>

          <template #main>
            <ul ref="pannel" class="goods-list">
              <li v-for="item in newHot" :key="item.id">
                <RouterLink to="/">
                  <img  alt="" v-imgLazy='item.picture' />
                  <p class="name">{{ item.title }}</p>
                  <p class="desc">{{ item.alt }}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </home-panel>
      </div>
    </div>
  </div>
</template>

<script>
// 轮播图板块
import HomeBanner from '@/views/home/components/home-banner.vue'
// 侧边栏板块
import HomeCategory from '@/views/home/components/home-categroy.vue'
// 主体区域
import HomePanel from './components/home-panel.vue'
// 导入抽离出去的逻辑
import { useHot } from './service/useHot'
import { useNew } from './service/useNew'
// import { ref } from 'vue'
// import { findHot, findNew } from '@/api/home'

export default {
  name: 'home',
  components: {
    HomeBanner,
    HomeCategory,
    HomePanel
  },
  setup () {
    // 新鲜好物
    // const newDate = ref([])
    // async function getNewDate () {
    //   const res = await findNew()
    //   // console.log(res.data.result)
    //   newDate.value = res.data.result
    // }

    // getNewDate()
    // // 人气推荐
    // const newHot = ref([])
    // async function getNewHot () {
    //   const res = await findHot()
    //   console.log(res)
    //   newHot.value = res.data.result
    // }
    // getNewHot()
    // 新鲜好物
    const { newDate } = useNew()
    // console.log(newDate)
    // 人气推荐
    const { newHot } = useHot()
    return {
      newDate,
      newHot
    }
  }
}
</script>

<style scoped lang='less'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406.008px;
  li {
    width: 306px;
    height: 406.008px;
    background: #f0f9f4;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22.008px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
